<!-- 车位车牌号-提交车位申请 -->

<template>
	<view>
		<view class="content">
			<view class="block__title">基本信息</view>

			<view class="cu-form-group">
				<view class="title">小区</view>
				{{plotNum}}
			</view>
			
			<view class="cu-form-group">
				<view class="title">选择房屋</view>
				<picker bindchange="PickerChange" :value="houseTypeIndex" :range="houseCarTypes" :range-key="'houseName'"
					@change="chooseHouseTypes">
					<view class="picker">
						{{houseCarTypes[houseTypeIndex].houseName?houseCarTypes[houseTypeIndex].houseName:'请选择'}}
					</view>
				</picker>
			</view>
			
			<view class="cu-form-group">
				<view class="title">车位名称</view>
				{{carName}}
			</view>

			<view class="cu-form-group">
				<view class="title">车牌号</view>
				<input v-model="plate" style="text-align:right" placeholder="请输入"></input>
			</view>

			<view class="cu-form-group">
				<view class="title">车位类型</view>
				<picker bindchange="PickerChange" :value="carType" :range="carTypes" :range-key="'carTypeName'"
					@change="chooseCarTypes">
					<view class="picker">
						{{carTypes[carType].carTypeName?carTypes[carType].carTypeName:'请选择'}}
					</view>
				</picker>
			</view>


		</view>
		<!-- 		<view class="content_box" v-if="homeMemberType == applyPersonId">
			<button @click="submitApply()" type="primary">提交申请</button>
		</view> -->
		<view class="content_box">
			<button @click="submitApply()" type="primary">提交</button>
		</view>
	</view>
</template>

<script>
	import context from '../../lib/java110/Java110Context.js'
	const constant = context.constant;
	import {
		getCurCommunity
	} from '../../api/community/communityApi.js'

	import {
		getProperty
	} from '../../api/property/propertyApi.js'


	export default {
		data() {
			return {
				houseCarTypes:'',
				houseTypeIndex:'',
				plotNum: '', //小区名
				plotCommunityId: '', //小区id
				houseId: '',
				phone:'',
				psId: '',
				num: '',
				carName: '',
				carType: "",
				plate: '',
				//车辆类型
				carTypes: [{
						carTypeName: '已售'
					},
					{
						carTypeName: '未售'
					},
					{
						carTypeName: '出租'
					}
				],
				page: 1,
				row: 2000,

				examineObjectId: 0,
				examineObjectName: "",
				examineType: "",
				proprietorId: 0,
				submitter: "",
				parkCount: '',
				userId: ''
			};
		},
		onLoad: function(options) {
			let _this = this;
			_this.parkCount = JSON.parse(options.car);
			_this.carName = _this.parkCount.examineObjectName
			_this.psId = _this.parkCount.examineObjectId
			console.log("_this.parkCount", _this.carName, _this.psId)

			let userIdName = uni.getStorageSync("commonUser");
			this.userId = userIdName.id
			
			_this.chooseCar()
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			let _plotNumCount = uni.getStorageSync("_selectCommunity");
			this.plotCommunityId = _plotNumCount.id
			this.plotNum = _plotNumCount.communityName
			// let houseNum = uni.getStorageSync("_selectHome");
			// this.houseId = houseNum.id
			// // this.plotNum = _plotNum.communityName + "小区";

			// if (_plotNum != null && _plotNum != undefined && _plotNum != '') {
			// 	this.plotNum = _plotNum.communityName + "小区";
			// 	this.plotCommunityId = _plotNum.id; //小区id
			// 	console.log("小区ID", this.plotCommunityId)
			// 	uni.setStorageSync('plotCommunityId', this.plotCommunityId);
			// }
		},
		methods: {
			
			
			// 选择已绑定的房屋
			chooseCar(){
				let commonUserNum = uni.getStorageSync("commonUser");
				this.phone = commonUserNum.phone; //小区id
				uni.request({
					url: constant.url.choiceHasHouse,
					header: context.getHeaders(),
					method: "GET",
					data: {
						phone: this.phone,
					},
					success: (res) => {
						this.houseCarTypes = res.data.result
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			
			chooseHouseTypes: function(e) {
				this.houseTypeIndex = e.target.value //取其下标
				this.houseId = this.houseCarTypes[this.houseTypeIndex].id //获取选中的数组
				console.log("this.houseId",this.houseId)
				// this.typeName = this.carTypes[this.houseTypeIndex].typeName //获取选中的数组
				// this.roleId = this.carTypes[this.houseTypeIndex].roleId //获取选中的数组
				// console.log("报修类型",this.roleId)
			},

			// 查询车位
			// loadCarNumber() {
			// 	let _that = this;

			// 	uni.request({
			// 		url: constant.url.queryCarNum,
			// 		header: context.getHeaders(),
			// 		POST: "GET",
			// 		data: {
			// 			communityId: this.plotCommunityId,
			// 		},
			// 		//动态数据
			// 		success: function(res) {
			// 			console.log("666", res.data); //成功情况下跳转
			// 			_that.parkScopes = res.data.data

			// 			console.log("车位编号", _that.parkScopes)
			// 			// }
			// 		},
			// 		fail: function(e) {
			// 			wx.showToast({
			// 				title: "服务器异常了",
			// 				icon: 'none',
			// 				duration: 2000
			// 			});
			// 		}
			// 	});
			// },

			// 车位位置
			// chooseCarPosition: function(e) {
			// 	this.parkIndex = e.target.value //取其下标
			// 	this.psId = this.parkScopes[this.parkIndex].psId;
			// 	this.num = this.parkScopes[this.parkIndex].num;
			// 	console.log("this.psId", this.psId, this.num)
			// },

			//车辆类型
			chooseCarTypes: function(e) {
				this.carType = e.target.value;
				console.log("this.carType", this.carType)
			},

			startDateChange: function(e) {
				this.startDate = e.detail.value
			},
			submitApply: function() {
				let obj = {
					"communityId": this.plotCommunityId,
					"houseId": this.houseId,
					"id": "",
					"ownerId": this.userId,
					"plate": this.plate,
					"propertyType": this.carType,
					"psId": this.psId

				};
				let msg = "";

				if (obj.submitter == "") {
					msg = "请填写申请人姓名";
				}
				if (msg != "") {
					wx.showToast({
						title: msg,
						icon: 'none',
						duration: 2000
					});
					return;
				}
				uni.request({
					url: constant.url.addCarList,
					header: context.getHeaders(),
					method: "POST",
					data: obj,
					success: function(res) {
						console.log("res车位", res)
						let _json = res.data;
						if (_json.code == 0 || _json.code == 200) {
							wx.showToast({
								title: "绑定成功",
								icon: 'none',
								duration: 2000
							});
							uni.navigateBack({
								url: '../parkingInfo/myParking',
							})
						}else if(_json.code == 500){
							wx.showToast({
								title: "该车位已绑定车辆，请勿重复绑定",
								icon: 'none',
								duration: 2000
							});
						}
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				});

			}
		}
	};
</script>
<style scoped lang="scss">
	.content {
		margin: 20rpx 30rpx;
		height: calc(100vh - 120rpx);
		overflow: auto;
	}

	.content_box {
		display: flex;
		position: absolute;
		bottom: 0rpx;
		width: 100%;
		height: 100rpx;
		justify-content: center;
		align-items: center;

		button {
			width: 400rpx;
			height: 70rpx;
			line-height: 70rpx;
			font-size: 26rpx;
			border-radius: 30rpx;
		}
	}

	.block__title {
		margin: 0;
		font-weight: 400;
		font-size: 14px;
		color: rgba(69, 90, 100, .6);
		padding: 40rpx 30rpx 20rpx;
	}

	.button_up_blank {
		height: 40rpx;
	}
</style>
